package com.demo.study.thread.self;

import java.util.concurrent.BlockingQueue;

/**
 * @author baymax
 * @since 2025-07-04
 */
public interface RejectHandler {
    void reject(Runnable command, SelfThreadPool pool);

    class ExceptionHandler implements RejectHandler {
        public void reject(Runnable command, SelfThreadPool pool) {
            throw new RuntimeException("任务队列已满");
        }
    }

    class DiscardHandler implements RejectHandler {
        public void reject(Runnable command, SelfThreadPool pool) {
            BlockingQueue<Runnable> blockQueue = pool.getBlockQueue();
            System.out.println("已丢弃一个任务");
            blockQueue.offer(command);
        }
    }
}
